package org.eoti.game.roshambo;

/**
 * The MIT License
 * <p/>
 * Copyright (c) 2009 Malachi de AElfweald (malachid@gmail.com)
 * <p/>
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * <p/>
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
 * Software.
 * <p/>
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
public class UPARuleMonger
extends RuleMonger<UPAWeapon, String, UPAPlayer>
{
	private enum Rule
	{
		RockRock(Judgement.Winner.Tie, "It's a tie!"),
		RockPaper(Judgement.Winner.Player2, "Scissors cover Rock"),
		RockScissors(Judgement.Winner.Player1, "Rock smashes Scissors"),
		RockFire(Judgement.Winner.Player2, "Fire scorches Rock"),
		RockWater(Judgement.Winner.Player1, "Rock blocks Water"),

		PaperRock(Judgement.Winner.Player1, "Paper covers Rock"),
		PaperPaper(Judgement.Winner.Tie, "It's a tie!"),
		PaperScissors(Judgement.Winner.Player2, "Scissors cut Paper"),
		PaperFire(Judgement.Winner.Player2, "Fire burns Paper"),
		PaperWater(Judgement.Winner.Player1, "Paper floats on Water"),

		ScissorsRock(Judgement.Winner.Player2, "Rock smashes Paper"),
		ScissorsPaper(Judgement.Winner.Player1, "Scissors cut Paper"),
		ScissorsScissors(Judgement.Winner.Tie, "It's a tie!"),
		ScissorsFire(Judgement.Winner.Player2, "Fire melts Scissors"),
		ScissorsWater(Judgement.Winner.Player1, "Scissors puncture the Water jug"),

		FireRock(Judgement.Winner.Player1, "Fire scorches Rock"),
		FirePaper(Judgement.Winner.Player1, "Fire burns Paper"),
		FireScissors(Judgement.Winner.Player1, "Fire melts Scissors"),
		FireFire(Judgement.Winner.Tie, "Everyone dies!"),
		FireWater(Judgement.Winner.Player2, "Water puts out Fire"),

		WaterRock(Judgement.Winner.Player2, "Rock blocks Water"),
		WaterPaper(Judgement.Winner.Player2, "Paper floats on Water"),
		WaterScissors(Judgement.Winner.Player2, "Scissors puncture the Water jug"),
		WaterFire(Judgement.Winner.Player1, "Water puts out Fire"),
		WaterWater(Judgement.Winner.Tie, "Everyone drowns!");
		
		Rule(Judgement.Winner winner, String description)
		{
			this.winner = winner;
			this.description = description;
		}
		private Judgement.Winner winner;
		private String description;
		public Judgement.Winner getWinner(){return winner;}
		public String getDescription(){return description;}
	}

	public Judgement<UPAWeapon, String, UPAPlayer> judge(Challenge<UPAWeapon, String, UPAPlayer> challenge)
	{
		UPAWeapon w1 = challenge.getPlayer1Weapon();
		UPAWeapon w2 = challenge.getPlayer2Weapon();
		Rule rule = Rule.valueOf(w1.name() + w2.name());
		return new Judgement<UPAWeapon, String, UPAPlayer>(
				challenge,
		    rule.getWinner(),
		    rule.getDescription()
		);
	}
}
